let id = 0;
// 依赖收集
class Dep {
  // 属性的dep要收集watcher
  constructor() {
    this.id = id++;
    // 这里存当前属性对应哪些watcher
    this.subs = [];
  }
  depend() {
    // 让这个watcher记住这个dep
    Dep.target.addDep(this);
  }
  // 记住这个watcher
  addSub(watcher) {
    this.subs.push(Dep.target);
  }
  // 通知watcher更新视图
  notify() {
    this.subs.forEach(watcher => watcher.update());
  }
}
// 让dep与watcher关联
Dep.target = null;
let stack = [];
export function pushTarget(watcher) {
  stack.push(watcher);
  Dep.target = watcher;
}
export function popTarget() {
  stack.pop();
  Dep.target = stack[stack.length - 1];
}
export default Dep;